package com.java.yz.mysql_jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/*
    JDBC实现模糊查询
 */
public class JdbcDemo6 {
    public static void main(String[] args) throws Exception{
        //获取数据连接对象
        Connection preparedStatement = MySQLTool.getPreparedStatement();

        //获取数据库操作对象
        PreparedStatement preparedStatement1 = preparedStatement.prepareStatement("select username,password from login where username like ?");


        //给占位符设置值
        preparedStatement1.setString(1,"张%");  //如果要查询中间字  %虎%

        //执行sql语句
        ResultSet resultSet = preparedStatement1.executeQuery();
        //得到一个结果集
        while (resultSet.next()){
            String name = resultSet.getString(1);
            String pas = resultSet.getString(2);
            System.out.println(name+"=="+pas);
        }
        //这样就可以查询到所有姓张的


    }
}
